package com.mokey.core.demo;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.mokey.core.annotation.Layout;
import com.mokey.core.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

@Layout(R.layout.activity_main)
public class MainActivity extends BaseActivity{
    @BindView(R2.id.navigation) BottomNavigationView navigationView;
    @BindView(R2.id.container) FrameLayout container;
    @BindView(R2.id.toolbar) Toolbar toolbar;
    private ImageView imageView;

    @Override
    protected void init(Bundle savedInstanceState) {
        initToolBar(toolbar,false);
        imageView = new ImageView(MainActivity.this);
        imageView.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT
        ));
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        int count = container.getChildCount();
        if(count==0){
            container.addView(imageView);
        }
        navigationView.offsetLeftAndRight(30);
        navigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.bank:
                        imageView.setImageResource(R.mipmap.bank);
                        break;
                    case R.id.paperplane:
                        imageView.setImageResource(R.mipmap.paperplane);
                        break;
                    case R.id.tag:
                        imageView.setImageResource(R.mipmap.tag);
                        break;
                    case R.id.settings:
                        imageView.setImageResource(R.mipmap.settings);
                        break;
                }
                return true;
            }
        });
    }

    @OnClick(R.id.okhttp)
    public void okhttp(){
        openActivity(OkhttpActivity.class);
    }
    @OnClick(R.id.retrofit)
    public void retrofit(){
        openActivity(RetrofitActivity.class);
    }
    @OnClick(R.id.common)
    public void common(){
        openActivity(CommonActivity.class);
    }
    @OnClick(R.id.widget)
    public void widget(){
        openActivity(WidgetActivity.class);
    }
}
